//
//  YZLListView.m
//  Car
//
//  Created by dllo on 15/11/2.
//  Copyright © 2015年 岳明. All rights reserved.
//

#pragma mark - **订阅标签列表

#import "YZLListView.h"
#import "Macro.h"
//#import "YZLShowOrHideView.h"

@interface YZLListView ()<yzlShowOrHideViewDelegate>

@property (nonatomic, strong) UILabel *blueLabel; /**< 点击订阅更多标签 */


@end

@implementation YZLListView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithRed:247 / 255.f green:247 / 255.f blue:247 / 255.f alpha:1];
        UILabel *fristLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, kWidth, 30)];
        fristLabel.font = [UIFont systemFontOfSize:14];
        fristLabel.text = @"点击删除";
        [self addSubview:fristLabel];
        fristLabel.textColor = [UIColor grayColor];
        
        self.showView = [[YZLShowOrHideView alloc] init];
        [self addSubview:self.showView];
        self.showView.delegate = self;
        self.showView.tag = 103;
        
        self.blueLabel = [[UILabel alloc] init];
        [self addSubview:self.blueLabel];
        self.blueLabel.backgroundColor = [UIColor colorWithRed:3 / 255.f green:124 / 255.f blue:1 alpha:1];
        self.blueLabel.textColor = [UIColor whiteColor];
        self.blueLabel.text = @"    点击订阅更多标签";
        self.blueLabel.font = [UIFont systemFontOfSize:15];
        
        self.hideView = [[YZLShowOrHideView alloc] init];
        [self addSubview:self.hideView];
        self.hideView.delegate = self;
        self.hideView.tag = 104;
        
        
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addTag:) name:@"addTag" object:@"addArray"];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deleteTag:) name:@"deleteTag" object:@"deleteArray"];
    [self layoutTheView];
   
    

}
- (void)layoutTheView {
    
    if (self.showArray.count % 4 == 0) {
        self.showView.frame = CGRectMake(0, 30, kWidth, kWidth / 7.5 * (self.showArray.count / 4));
    } else self.showView.frame = CGRectMake(0, 30, kWidth, kWidth / 7.5 * (self.showArray.count / 4 + 1));
    self.showView.isShow = YES;
    self.blueLabel.frame = CGRectMake(0, 30 + self.showView.frame.size.height, kWidth, 30);
    
    self.hideView.frame = CGRectMake(0, self.blueLabel.frame.origin.y + self.blueLabel.frame.size.height + 10, kWidth, kHeight - self.blueLabel.frame.origin.y + self.blueLabel.frame.size.height);
    self.hideView.isShow = NO;
}

- (void)addTag:(NSNotification *)noti {
    self.showArray = [noti.userInfo objectForKey:@"showArray"];
    [self.showView.collectionView reloadData];
    [self layoutTheView];
}

- (void)deleteTag:(NSNotification *)noti {
    self.hideArray = [noti.userInfo objectForKey:@"hideArray"];

    [self.hideView.collectionView reloadData];
    [self layoutTheView];
}

- (void)setShowArray:(NSArray *)showArray {
    if (_showArray != showArray) {
        _showArray = showArray;
    }
    
    
    _showView.array = showArray;
    
    
}

- (void)setHideArray:(NSArray *)hideArray {
    if (_hideArray != hideArray) {
        _hideArray = hideArray;
    }
    _hideView.array = hideArray;
//    _showView.isShow = NO;
}

- (void)clickOnDeleteOrAddWithIndexPath:(NSIndexPath *)indexPath withView:(UIView *)view {
    if (view.tag == 103) {
        [self.delegate clickOnAddTagWithIndexPath:indexPath];
    } else if (view.tag == 104) {
        [self.delegate clickOnDeleteTagWithIndexPath:indexPath];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
